package com.sc.ppx_api.controller;

import com.sc.ppx_api.pojo.Videos;
import com.sc.ppx_api.service.IVideosService;
import com.sc.ppx_api.utils.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 视频信息表 前端控制器
 * </p>
 *
 * @author victory
 * @since 2025-09-23 02:48:44
 */
@RestController
@RequestMapping("/videos")
public class VideosController {
    @Autowired
    IVideosService videosService;

    @RequestMapping("allVideos")
    ResponseMsg allVideos(){
        List<Videos> videos = videosService.list();
        return ResponseMsg.getInstance(200, videos);
    }

    @RequestMapping("getOneById")
    ResponseMsg getOneById(@RequestParam Integer id){
        if (null != id){
            Videos video = videosService.getById(id);
            return ResponseMsg.getInstance(ResponseMsg.SUCCESS, video);
        }
        return ResponseMsg.getInstance(ResponseMsg.ERROR, "未找到相关视频");
    }

    //点击增加热度(+1)
    @RequestMapping("view")
    ResponseMsg increaseByView(@RequestParam Integer id){
        if (null != id){
            Videos video = videosService.getById(id);
            video.setHot(video.getHot()+1);
            return ResponseMsg.getInstance(ResponseMsg.SUCCESS, "热度+1");
        }
        return ResponseMsg.getInstance(ResponseMsg.ERROR, "未找到相关视频");
    }

    //点赞增加热度(+2)
    @RequestMapping("like")
    ResponseMsg increaseByLike(@RequestParam Integer id){
        if (null != id){
            Videos video = videosService.getById(id);
            video.setHot(video.getHot()+2);
            return ResponseMsg.getInstance(ResponseMsg.SUCCESS, "热度+2");
        }
        return ResponseMsg.getInstance(ResponseMsg.ERROR, "未找到相关视频");
    }

    //收藏增加热度(+2)
    @RequestMapping("favorite")
    ResponseMsg increaseByFavorite(@RequestParam Integer id){
        if (null != id){
            Videos video = videosService.getById(id);
            video.setHot(video.getHot()+2);
            return ResponseMsg.getInstance(ResponseMsg.SUCCESS, "热度+2");
        }
        return ResponseMsg.getInstance(ResponseMsg.ERROR, "未找到相关视频");
    }

    //评论增加热度(+3)
    @RequestMapping("comment")
    ResponseMsg increaseByComment(@RequestParam Integer id){
        if (null != id){
            Videos video = videosService.getById(id);
            video.setHot(video.getHot()+3);
            return ResponseMsg.getInstance(ResponseMsg.SUCCESS, "热度+3");
        }
        return ResponseMsg.getInstance(ResponseMsg.ERROR, "未找到相关视频");
    }

}
